home *** CD-ROM | disk | FTP | other *** search
/ Best of Shareware / Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso / mac / DOS / TELECOMM / PCCP047 / MESSOUT.C < prev    next >
Text File  |  1992-08-25  |  4KB  |  194 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  *    MicroSoft QuickC
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<bios.h>
  7. #include<dos.h>
  8. #include<fcntl.h>
  9. #include<sys\types.h>
  10. #include<sys\stat.h>
  11. #include<signal.h>
  12. #include<process.h>
  13. #include"port.h"
  14.  
  15. sendchar(c)
  16.     unsigned char c;
  17.     {
  18.     while(!((inp(basereg+STATREG)&TXMTMASK)&&(inp(basereg+MSTATREG)&CTSMASK)))
  19.         if(kbhit())
  20.             getch();
  21.     outp(basereg, c);
  22.     }
  23.  
  24. int follow;
  25.  
  26. quit()
  27.     {
  28.     cleanup(0);
  29.     exit(99);
  30.     }
  31.  
  32. sendstr(str)
  33.     char *str;
  34.     {
  35.     int i;
  36.     for(i=0;str[i]!='\0';++i)
  37.         if(str[i]=='\n')
  38.             {
  39.             sendchar('\r');
  40.             sendchar('\n');
  41.             }
  42.         else
  43.             sendchar(str[i]);
  44.     }
  45.  
  46. portgets(str)
  47.     char *str;
  48.     {
  49.     int i;
  50.     i=0;
  51.     while(i<255)
  52.         {
  53.         while(follow==index)
  54.             {
  55.             if(!(inp(basereg+MSTATREG)&DCDMASK))
  56.                 return(-1);
  57.             if(kbhit())
  58.                 getch();
  59.             }
  60.         str[i]=buf[follow++];
  61.         follow%=TBUFSIZ;
  62.         if(str[i]=='\b')
  63.             if(i>0)
  64.                 {
  65.                 i-=2;
  66.                 sendchar('\b');
  67.                 sendchar(' ');
  68.                 sendchar('\b');
  69.                 }
  70.             else
  71.                 {
  72.                 i--;
  73.                 sendchar(0x07);
  74.                 }
  75.         else
  76.             sendchar(str[i]);
  77.         if((str[i]=='\r')||(str[i]=='\n'))
  78.             {
  79.             sendchar('\r');
  80.             sendchar('\n');
  81.             str[i]='\0';
  82.             break;
  83.             }
  84.         i++;
  85.         }
  86.     str[255]='\0';
  87.     return(0);
  88.     }
  89.         
  90. main(argc, argv)
  91.     int argc;
  92.     char **argv;
  93.     {
  94.     FILE *fd;
  95.     long timestamp;
  96.     int i, j, outfd, ok, c, run, result;
  97.     char str[256], filename[256], str1[256];
  98.     index=follow=0;
  99.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  100.     if(!strcmp(getenv("REMOTE"), "YES"))
  101.         {
  102.         printf("You appear to be already logged in remotely, judging by the environment\n");
  103.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  104.         printf("Are you sure you want to run MESSIN? (y or n) --> ");
  105.         if(getchar()!='y') /* Note getchar() and not getch()! */
  106.             {
  107.             printf("I didn't think so!\n");
  108.             exit(99);
  109.             }
  110.         else
  111.             printf("OK, you're the boss!");
  112.         }
  113.     printf("Control-C to Exit.\n");
  114.     if(argc!=4)
  115.         {
  116.         printf("USAGE: messin <comnum> <bps> <directory>\n");
  117.         exit(1);
  118.         }
  119.     comnum=atoi(argv[1])-1;
  120.     speed=atoi(argv[2]);
  121.     databits='8';
  122.     parity='n';
  123.     stopbits='1';
  124.     setport();
  125.     readset();
  126.     setup();
  127.     signal(SIGINT, quit);
  128.     sprintf(str, "\nEnter your account name: --> ");
  129.     sendstr(str);
  130.     if(portgets(str)==-1)
  131.         {
  132.         printf("Lost carrier detect.\n");
  133.         exit(10);
  134.         }
  135.     for(i=(strlen(str)-1);i>=0;i--)
  136.         if((str[i]=='\\')||(str[i]=='/'))
  137.             {
  138.             sprintf(str, "Backslash and slash are not permitted!\n");
  139.             sendstr(str);
  140.             exit(11);
  141.             }
  142.     printf("MESSOUT called on account %s.\n", str);
  143.     sprintf(filename, "%s\\%s", argv[3], str);
  144.     if((fd=fopen(filename, "r"))==NULL)
  145.         {
  146.         sprintf(str, "Sorry, can't open the file.\n");
  147.         sendstr(str);
  148.         printf("Error opening MESSOUT file.\n");
  149.         exit(1);
  150.         }
  151.     i=0;
  152.     while(1)
  153.         {
  154.         i++;
  155.         if(fgets(str, 80, fd)==NULL)
  156.             {
  157.             sprintf(str, "*** END OF MESSAGE. PRESS ANY KEY TO CONTINUE --> ");
  158.             sendstr(str);
  159.             while(follow==index)
  160.                 {
  161.                 if(!(inp(basereg+MSTATREG)&DCDMASK))
  162.                     {
  163.                     cleanup();
  164.                     exit(10);
  165.                     }
  166.                 if(kbhit())
  167.                     getch();
  168.                 }
  169.             follow=index;
  170.             exit(0);
  171.             }
  172.         sendstr(str);
  173.         if(!(i%20))
  174.             {
  175.             sprintf(str, "PRESS ANY KEY TO CONTINUE: --> ");
  176.             sendstr(str);
  177.             while(index==follow)
  178.                 {
  179.                 if(kbhit())
  180.                     getch();
  181.                 if(!(inp(basereg+MSTATREG)&DCDMASK))
  182.                     {
  183.                     cleanup();
  184.                     exit(10);
  185.                     }
  186.                 }
  187.             follow=index;
  188.             sprintf(str, "\n");
  189.             sendstr(str);
  190.             }
  191.         }
  192.     exit(0);
  193.     }
  194.